package whf.framework.web.query;

import whf.framework.util.StringUtils;

/**
 * @author wanghaifeng
 *
 */
public class NumberField extends Field {
	public NumberField(String name, String[] values){
		super(name, values);
	}
	
	@Override
	public String toHQLString() {
		StringBuilder sb = new StringBuilder("(");
		if(StringUtils.isNumeric(values[0])){
			sb.append("t.").append(name).append(">=").append(values[0]);
		}
		if(values.length == 2 && StringUtils.isNumeric(values[1])){
			if(!"(".equals(sb.toString())) {
				sb.append(" and ");
			}
			sb.append("t.").append(name).append("<=").append(values[1]);
		}
		sb.append(")");
		if("()".equals(sb.toString()))
			return "";
		else
			return sb.toString();
	}

}
